package com.diandian.backend.store.controller;

import com.diandian.backend.store.param.*;
import com.diandian.backend.store.service.OfflineStoreOpenApiService;
import com.diandian.base.boot.starter.response.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * [门店]线下门店Open API
 */
@RestController
@RequestMapping("/offline/store/open/api")
public class OfflineStoreOpenAPIController {

    @Autowired
    private OfflineStoreOpenApiService offlineStoreOpenApiService;

    /**
     * 1. 查询全部门店编码数据
     * 2. 批量同步门店数据（有则更新，无则新增），每次不能超过100条
     * 3. 分页查询门店数据，每次不能超过100条
     */

    @PostMapping("/page")
    public BaseResult getStorePage(@RequestBody OfflineStoreOpenApiPageParam param) {
        param.check();
        return new BaseResult(0, "success", offlineStoreOpenApiService.page(param.toDTO()));
    }

    @PostMapping("/code/list")
    public BaseResult getAllStoreCodeList(@RequestBody OfflineStoreQueryAllStoreCodeParam param) {
        param.check();
        return new BaseResult(0, "success", offlineStoreOpenApiService.getAllStoreCodeList(param.getBelong(), param.getOrgId(), param.getOrgCode()));
    }

    @PostMapping("/batchSync")
    public BaseResult batchSyncStore(@RequestBody OfflineStoreBatchAddParam param) {
        param.check();
        offlineStoreOpenApiService.batchSyncStore(param);
        return new BaseResult(0, "success", null);
    }


}